#@DESC:
#@TODO: 
class Database:
  def __init__(self):
    #terrain = csv.reader(open('terrains.csv'))
    self.terrain = readTable('terrains.csv')
    self.units = readTable('units.csv')
    self.squads = readTable('squads.csv')
    self.weapons = readTable('weapons.csv')

  def getSquad(self,name):
    ret = Squad(name,name,self.squads[name]['icon'])
    counter = range(int(self.squads[name]['unit_count'])+1)[1:]
    for unit_id in counter:
      type = self.squads[name]['unit'+str(unit_id)]
      if self.units[type]['type'] == 'transport':
        ret.motorized_state = 'loaded'  
      unit = Unit(type,type,150,3,7,10)
      
      ret.units.append(unit)
    return ret
    
  def getUnitInfo(self,unit_name):
    return self.units[unit_name]
    
  def getWeaponInfo(self,weapon_name):
    if weapon_name in self.weapons:
      return self.weapons[weapon_name]
    else:
      return None
